<?php
class Historique{
    protected $historique;
    protected $current;
    static $instance;
    private function __construct(){
        $this->historique=array();
        $this->current=0;
    }

    static function getInstance(){
       if(!isset(self::$instance))self::$instance=new Historique();

       return self::$instance;
    }
    public function previous(){
        $this->current--;

    }
    public function following(){
        $this->current++;
    }
    public function appendHistorique($appendPost=true){
       
        $len=$this->current+1;
        $this->historique[$len]['url']=$_SERVER['REQUEST_URI'];
        if(isset($_POST) && count($_POST)>0 && $appendPost)$this->historique[$len]['post']=$_POST;
        else $this->historique[$len]['post']= false;
        $this->current=$len;
    }

    function pickUrl($prev=true){

        if($prev)
            $cont= (isset($this->historique[$this->current]))?$this->historique[$this->current]['url']:null;
        else {
            $cont= (isset($this->historique[$this->current+1]))?$this->historique[$this->current+1]['url']:null;
        }
     
        return $cont;
    }
    function pickPost($prev=true){
        if($prev)
            $cont= (isset($this->historique[$this->current]))?$this->historique[$this->current]['post']:null;
        else {
            $cont= (isset($this->historique[$this->current+1]))?$this->historique[$this->current+1]['post']:null;
        }
        return $cont;
    }

    function isLast(){
        
        return ($this->current==count($this->historique));
    }
}
?>